package com.qxsx.midi.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.activity.study.MidiManDetailsActivity;
import com.qxsx.midi.activity.study.StudyClubDetailActivity;
import com.qxsx.midi.fragment.StudyFragment;
import com.qxsx.midi.model.StudyListItem;
import com.qxsx.midi.utils.MyNet;

import java.util.ArrayList;
import java.util.List;

public class StudySearchRltListAdapter extends BaseAdapter {
    private Context context;

    private List<StudyListItem> lists = new ArrayList<>();

    public StudySearchRltListAdapter() {
    }

    public StudySearchRltListAdapter(Context context, List<StudyListItem> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }


    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }


    public long getItemId(int position) {
        return position;
    }

    public void RemoveAll() {
        this.lists.clear();
    }

    public void AddData(List<StudyListItem> lists) {
        for (StudyListItem it : lists) {
            this.lists.add(it);
        }
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_list_study, null);
            viewHolder.title = (TextView) convertView.findViewById(R.id.study_list_item_title);
            viewHolder.desc = (TextView) convertView.findViewById(R.id.study_list_item_desc);
            viewHolder.iv_myexam = (ImageView) convertView.findViewById(R.id.iv_myexam);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(lists.get(position).get_title());
        viewHolder.desc.setText(lists.get(position).get_desc());
        MyNet.setNetImage(context, viewHolder.iv_myexam, lists.get(position).get_icon());
        return convertView;
    }

    static class ViewHolder {
        TextView title;
        TextView desc;
        ImageView iv_myexam;
    }

}
